package com.jet.merchant.gate;

import com.jet.merchant.domain.dto.PowerCreateDto;
import com.jet.merchant.domain.entity.ClerkRole;
import com.jet.merchant.domain.vo.PowerVo;
import com.jet.merchant.service.IClerkRoleService;
import com.jet.core.result.ResultJson;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dcl
 * @date 2023-02-26 16:22:48
 */
@RestController
@RequestMapping("/gate/clerk/role")
public class GateRoleController {

    private final IClerkRoleService clerkRoleService;

    public GateRoleController(IClerkRoleService clerkRoleService) {
        this.clerkRoleService = clerkRoleService;
    }

    @GetMapping("/list")
    public ResultJson<List<ClerkRole>> list(@RequestHeader long merchantNo,
                                            @RequestHeader long storeNo,
                                            @RequestHeader String accountId) {
        List<ClerkRole> vo = clerkRoleService.list(merchantNo);
        return ResultJson.ok(vo);
    }

    @PostMapping("/power-checked/{id}")
    public ResultJson<Void> powerMenuCreate(@RequestHeader long merchantNo,
                                            @RequestHeader long storeNo,
                                            @RequestHeader String accountId,
                                            @PathVariable("id") String id,
                                            @RequestBody List<PowerCreateDto> dtos) {
        clerkRoleService.powerCreate(merchantNo, id, dtos);
        return ResultJson.ok();
    }

    @GetMapping("/power")
    public ResultJson<List<PowerVo>> powerMenu(@RequestHeader long merchantNo,
                                               @RequestHeader long storeNo,
                                               @RequestHeader String accountId) {
        List<PowerVo> vos = clerkRoleService.powerMenu(merchantNo, accountId);
        return ResultJson.ok(vos);
    }

    @GetMapping("/power-checked/{roleId}")
    public ResultJson<List<String>> powerMenuChecked(@RequestHeader long merchantNo,
                                                     @RequestHeader long storeNo,
                                                     @RequestHeader String accountId,
                                                     @PathVariable("roleId") String id) {
        List<String> vos = clerkRoleService.powerMenuChecked(merchantNo, id, accountId);
        return ResultJson.ok(vos);
    }
}
